<?php
namespace Home\Controller;
use Think\Controller;
class DetailController extends BaseController {
    
	public function index(){
		$id=$_GET["id"];
		$islogin=$this->islogin();
		if($islogin==false){
			$this->display("Public:login");
			exit;
		}
		
		if($id){
			$article =M('article');
			$article_list=$article->where("article_id=$id")->find();
		    $this->assign('article_list', $article_list);
		    
		    
		    //去附件列表
		    $file =M('file');
		    $file_list=$file->where("article_id=$id")->select();
		    $this->assign('file_list', $file_list);
		    
		    $file_count=$file->where("article_id=$id")->count();
		    $this->assign('file_count', $file_count);
		}
		
        $this->display("detail");
    }
    
	public function pic_detail(){
		$id=$_GET["id"];
		$islogin=$this->islogin();
		if($islogin==false){
			$this->display("Public:login");
			exit;
		}
		
		if($id){
			$pic = M('pic');
			$pic_list=$pic->where("id=$id")->find();
		    $this->assign('pic_list', $pic_list);
		    
		    
		    //去附件列表
//		    $file =M('file');
//		    $file_list=$file->where("article_id=$id")->select();
//		    $this->assign('file_list', $file_list);
//		    
//		    $file_count=$file->where("article_id=$id")->count();
//		    $this->assign('file_count', $file_count);
		}
		
        $this->display("pic_detail");
    }
    
    
    public function down(){
    	$fileid=$_GET["fn"];
    	$detailid=$_GET["did"];
    	$file =M('file');
    	$fileone=$file->where("id=$fileid")->find();
    	$file_name=$fileone["file_name"];
    	
    	if( empty($_GET["fn"])){
   			 $this->error("非法链接",'/index.php/Home/Detail/Index?id='.$detailid);
   			 exit;
		}
//		$file_dir = "E:\\wamp/www/ceping/Public/upload/file/annex";
		$php_path = dirname(__FILE__) . '/';
		$file_dir=$php_path."../../../Public/upload/file/annex";
		
		$file_dir = $file_dir."/";
		if   (!file_exists($file_dir.$file_name))   {   //检查文件是否存在  
		
			  $this->error("附件不存在",'/index.php/Home/Detail/Index?id='.$detailid);
			  exit;    
		}   else   {  
			$file = fopen($file_dir . $file_name,"r"); // 打开文件
			// 输入文件标签
			Header("Content-type: application/octet-stream");
			Header("Accept-Ranges: bytes");
			Header("Accept-Length: ".filesize($file_dir . $file_name));
			Header("Content-Disposition: attachment; filename=" . $file_name);
			// 输出文件内容
			echo fread($file,filesize($file_dir . $file_name));
			fclose($file);
			exit();
		}

    }
    
    
	public function Feedback(){
		$id=$_GET["id"];
		
		if($id){
			
		$feedback =M('feedback');
		$feedback_list=$feedback->where("id=$id")->find();
	    $this->assign('feedback_list', $feedback_list);
        
		}
		
		
        $this->display("feedbackdetail");
    }
    
}